/**
 * 轮播图js
 */

$(function () {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-56});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url: '../../sys/broadcastsupply/list?_' + $.now(),
		height: $(window).height()-56,
		queryParams: function(params){
			params.name = vm.keyword;
			params.type = 2;
			return params;
		},
		columns: [
			{checkbox: true},
			{field : "createTime", title : "创建时间", width : "100px"}, 
			{field : "img", title : "图片", width : "100px"}, 
			{field : "url", title : "链接", width : "100px"}, 
			{field : "level", title : "级别", width : "100px"}, 
			{
				field : "status",
				title : "可用",
				width : "60px",
				align : "center",
				formatter : function(value, row, index) {
					if (value == 1) {
						return '<i class="fa fa-toggle-on"></i>';
					}
					if (value == 2) {
						return '<i class="fa fa-toggle-off"></i>';
					}
				}
			},
		]
	})
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
		keyword: null
	},
	methods : {
		load: function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save: function() {
			dialogOpen({
				title: '新增轮播图',
				url: 'base/broadcastsupply/add.html?_' + $.now(),
				width: '420px',
				height: '350px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if(checkedRow(ck)){
				dialogOpen({
					title: '编辑轮播图',
					url: 'base/broadcastsupply/edit.html?_' + $.now(),
					width: '420px',
					height: '350px',
					success: function(iframeId){
						top.frames[iframeId].vm.broadcast.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes: function(iframeId){
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];	
			if(checkedArray(ck)){
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url: '../../sys/broadcast/remove?_' + $.now(),
			    	param: ids,
			    	success: function(data) {
			    		vm.load();
			    	}
				});
			}
		}
	}
})